Skip to content

Conversation

@BrandoDev
Copy link

This pull request introduces several improvements and updates to the brawlpy library, focusing on improving usability, code readability, and functionality. The most significant changes include the addition of an asynchronous context manager for the Client class, refactoring of code for consistency and clarity, and updates to the README.md documentation.

Enhancements to Client functionality:

  • Added asynchronous context manager methods (__aenter__ and __aexit__) to the Client class, allowing the use of async with for managing the client session lifecycle. ([brawlpy/main.pyL4-R66](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L4-R66))
  • Refactored the request method in the Client class to handle session initialization errors and improve error handling. ([brawlpy/main.pyL4-R66](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L4-R66))
  • Updated various Client methods (get_player, get_club, brawlers, events, etc.) to use consistent string formatting and improved object creation for better readability. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L40-R142), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L113-R206), [[3]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L143-R246), [[4]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L179-R284), [[5]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L211-R334), [[6]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L249-R377))

Documentation updates:

  • Updated the README.md to reflect the addition of the context manager for the Client class and corrected the installation command to point to the new repository URL. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L12-R16), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L25-R25), [[3]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R37), [[4]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R55))

Codebase cleanup and consistency:

  • Replaced single quotes with double quotes across the codebase for consistency. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-e5556f1147ae675e7061baebb2e7cddb9cc1d9006f03a765720373d6c3a2ab39L1-R3), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-2bf9fd80d007a3cb5d23139ad5bc9470436f2600e5389ca46ad74ac8cb11a833R20-R85), [[3]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L40-R142))
  • Refactored imports in brawlpy/__init__.py and brawlpy/main.py to explicitly list imported classes and objects, improving clarity and reducing wildcard imports. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-d41c6849699852c678513a728c4873b8775605d8bdc527a3023671d786dad7fcL11-R47), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L4-R66))
  • Removed unused imports and redundant code in brawlpy/errors.py and other files. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-2bf9fd80d007a3cb5d23139ad5bc9470436f2600e5389ca46ad74ac8cb11a833R10), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L4-R66))

Bug fixes and minor improvements:

  • Fixed a trailing comma issue in brawlpy/icons.py to adhere to JSON formatting standards. ([brawlpy/icons.pyL55-R55](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-fa51c3a021755e8ac61ec64529779176eb6aeb90b07ba5e2457167d09d129362L55-R55))
  • Improved error messages and handling in custom exceptions, ensuring better debugging information is provided. ([[1]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-2bf9fd80d007a3cb5d23139ad5bc9470436f2600e5389ca46ad74ac8cb11a833R20-R85), [[2]](https://github.com/PyStarr/BrawlPy/pull/4/files#diff-7cc0a1ecc2a1c7abbc754e5233bba68d768b7c92bacaa599c40be70f85c52b13L40-R142))

@BrandoDev BrandoDev marked this pull request as ready for review July 11, 2025 14:38
Copilot AI review requested due to automatic review settings January 18, 2026 15:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the brawlpy library to version 1.3.0 with improvements focused on modern async patterns, code formatting consistency, and documentation. The main enhancement is adding async context manager support to the Client class for better session lifecycle management.

Changes:

  • Added async context manager (__aenter__ and __aexit__) methods to Client class for proper session management
  • Standardized code formatting by replacing single quotes with double quotes and improving code consistency
  • Updated examples and README to demonstrate context manager usage

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
setup.py Reformatted with double quotes and improved spacing consistency
examples/player.py Updated to use async context manager pattern
examples/club.py Updated to use async context manager pattern
brawlpy/utils.py Improved formatting and updated imports
brawlpy/objects.py Reformatted with consistent spacing and removed nameColor parameter from Player
brawlpy/main.py Added context manager support, refactored session management, improved error handling
brawlpy/icons.py Standardized dictionary formatting with double quotes
brawlpy/errors.py Reformatted with double quotes for consistency
brawlpy/init.py Replaced wildcard imports with explicit imports and updated version to 1.3.0
brawlpy/API.py Removed unused imports and reformatted
README.md Updated documentation to show context manager usage and corrected repository URL

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +113 to +128
Pl = Player(
player["name"],
player["tag"],
player["icon"]["id"],
player["trophies"],
player["expLevel"],
player["expPoints"],
cl,
player["highestTrophies"],
player["soloVictories"],
player["duoVictories"],
player["3vs3Victories"],
player["bestRoboRumbleTime"],
player["bestTimeAsBigBrawler"],
brrs,
)
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Player object instantiation is missing the battleLog parameter. The Player class constructor expects battleLog as the last parameter, but this code doesn't provide it. The old code had a call to get_battle_log that was removed but the parameter was never added here. This will cause a TypeError when creating a Player object.

Copilot uses AI. Check for mistakes.
Comment on lines 51 to 55
def __init__(self, url, code, text):
self.code = code
self.url = url
self.message = f'An unexpected error has occured.\n{text}'
self.message = f"An unexpected error has occured.\n{text}"
super().__init__(self.code, self.message)
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UnexpectedError constructor signature has inconsistent parameter order. The init method defines parameters as (url, code, text), but all call sites in main.py pass them as (status, url, ""). This will cause url to be assigned to code and "" to be assigned to url, breaking error reporting.

Copilot uses AI. Check for mistakes.
url="https://github.com/PyStarr/BrawlPy",
long_description=long_description,
long_description_content_type="text/markdown",
download_url="https://github.com/PyStarr/BrawlPy/archive/v1.2.5.tar.gz",
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The download_url still references version "1.2.5" in the archive URL, but should be updated to "1.3.0" to match the new version number.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback



class UnexpectedError(Errors):
"""Raised if an unknown error has occured."""
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "occured" should be "occurred" (double 'r').

Copilot uses AI. Check for mistakes.
Comment on lines +348 to +359
rankgs.append(
BrawlerRanking(
"",
each["tag"],
each["name"],
each["nameColor"],
each["icon"]["id"],
each["trophies"],
each["rank"],
cl,
)
)
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BrawlerRanking constructor is being called with an empty string as the first parameter for 'brawler'. According to the BrawlerRanking class definition, the first parameter should be the brawler name or identifier, not an empty string. The API response should contain brawler information that needs to be extracted and passed here.

Copilot uses AI. Check for mistakes.
def __init__(self,code,countryCode = None):
def __init__(self, code, countryCode=None):
self.code = code
if id:
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition uses 'id' instead of 'countryCode'. This is a copy-paste error from the BrawlerNotFound exception above. It should check 'if countryCode:' to properly set the error message.

Suggested change
if id:
if countryCode:

Copilot uses AI. Check for mistakes.
Comment on lines +71 to 76
def __init__(self, code, id=None):
self.code = code
if id:
self.message = 'Invalid ID passed! {}'.format(id)
self.message = "Invalid ID passed! {}".format(id)

super().__init__(self.code, self.message)
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BrawlerNotFound exception doesn't initialize self.message when id is None or falsy. This will cause an AttributeError when the exception is raised without an id parameter, since str tries to access self.message.

Copilot uses AI. Check for mistakes.
)
name="brawlpy",
packages=["brawlpy"],
version="1.2.5",
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version number in setup.py is still "1.2.5" but the PR title mentions updating to "1.3.0" and version in init.py has been updated to "1.3.0". These should be consistent.

Copilot uses AI. Check for mistakes.
self.code = code
self.url = url
self.message = f'An unexpected error has occured.\n{text}'
self.message = f"An unexpected error has occured.\n{text}"
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "occured" should be "occurred" (double 'r').

Copilot uses AI. Check for mistakes.
BrandoDev and others added 2 commits January 18, 2026 17:57
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant